<style lang="less">
    .title-text span {
        display: block; /*设置为块级元素会独占一行形成上下居中的效果*/
        position: relative; /*定位横线（当横线的父元素）*/

        color: black; /*居中文字的颜色*/
        font-weight: bold;
        text-align: center;
    }

    .title-text span:before, .title-text span:after {
        content: '';
        position: absolute; /*定位背景横线的位置*/
        top: 50%;
        background: #dfdfdf; /*背景横线颜色*/
        width: 44%; /*单侧横线的长度*/
        height: 1px;
    }

    .title-text span:before {
        left: 0; /*调整背景横线的左右距离*/
    }

    .title-text span:after {
        right: 0;
    }

    .leaveComments {
        position: fixed;
        top: 50%;
        right: 10%;
        transform: translateY(-50%);
        margin-top: 40px;
        z-index: 99;
    }

    .leaveComments .detail_comment {
        position: absolute;
        background-color: white;
        width: 234px;
        height: 264px;
        box-shadow: 0px 0px 18px #ccc;
        top: -220px;
        right: 0px;
        transition: left 2s;
    }

    .leaveComments .detail_comment > h2 {
        background-color: #0D8EF5;
        font-weight: normal;
        font-size: 16px;
        color: white;
        padding: 5px 0px 5px 10px;
        line-height: 20px;
    }

    .leaveComments .detail_comment p {
        margin: 10px;
    }

    .leaveComments .detail_comment textarea {
        outline: none;
        resize: none;
        width: 100%;
        border-color: #ccc;
    }

    .selectOption .ivu-select-dropdown-list {
        max-height: 200px;
        overflow: auto;
    }
</style>
<template>
    <card>
        <div class="search" style="background-color: rgb(255,255,255)">
            <Row>
                <Form inline :label-width="120">
                    <Form-item style="float: right;">
                        <Button id="saveButton" v-if="this.modelType != 2 && this.saveType==4"
                                @click="Save('netCarCompanyForm')" type="primary" size="large"
                                style="margin-right:24px;border: none;">保存
                        </Button>
                        <Button id="commitButton" v-if="this.modelType != 2" @click="Commit('netCarCompanyForm')"
                                type="primary" size="large" style="margin-right:24px;color:white;">提交
                        </Button>
                        <!--                    <Button id="applyButton" v-if="this.modelType == 2 && this.showType == 1"-->
                        <!--                            @click="blacklist('netCarCompanyForm')" type="primary" size="large"-->
                        <!--                            style="margin-right:24px;color:white;">黑名单申请-->
                        <!--                    </Button>-->
                        <Button @click="closeThisTag" type="primary" size="large"
                                style="color:white;">返回
                        </Button>
                        <Spin size="large" fix v-if="spinShow"></Spin>
                    </Form-item>
                </Form>
            </Row>
            <div class="addInfo">
                <h2 class="title-text"><span>网约车挂靠信息</span></h2>
                <Form ref="netCarCompanyForm" :model="netCarCompanyForm" :rules="netCarCompanyFormValidate"
                      :label-width="200">
                    <Row>
                        <i-col span="8">
                            <Form-item label="运营公司名称" prop="affiliatedName">
                                <Input v-bind:disabled="netCarCompanyForm.disabled" type="text" size="default"
                                       v-model="netCarCompanyForm.affiliatedName" clearable placeholder="请输入"
                                       style="width: 200px"/>
                            </Form-item>
                        </i-col>
                        <i-col span="8">
                            <Form-item label="社会统一信用代码" prop="socUniCrtCode">
                                <Input v-bind:disabled="is.disabled" type="text" size="default"
                                       v-model="netCarCompanyForm.socUniCrtCode" clearable placeholder="请输入"
                                       style="width: 200px" maxlength="18" @keyup.native="socValite"/>
                            </Form-item>
                        </i-col>
                        <i-col span="8">
                            <Form-item label="已运营年限" prop="operationYears">
                                <Input disabled="disabled" type="text" size="default"
                                       v-model="netCarCompanyForm.operationYears" clearable placeholder="请输入"
                                       style="width: 200px"/>
                            </Form-item>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col span="8">
                            <div v-for="(item,index) in netCarCompanyForm.addressinfotwo" :key="index">
                                <FormItem label="运营城市" :prop="'addressinfotwo['+index+'].detailAddresstwo'"
                                          :style="{'z-index':'99'-index,'position':'relative'}"
                                          :rules="{required: true, message: '请选择运营城市', trigger: 'change',type:'array'}">
                                    <Cascader v-bind:disabled="netCarCompanyForm.disabled" :load-data="loadData"
                                              :data="location" style="width:200px;" size="default"
                                              v-model="item.detailAddresstwo" placeholder="下拉选择省市"
                                              class="show_cascader_input" :clearable="false">
                                    </Cascader>
                                </FormItem>
                            </div>
                        </i-col>
                        <i-col span="8">
                            <Form-item label="注册时间" prop="foundedTime">
                                <Date-picker :options="options" @on-change="changeOperationYears" v-bind:disabled="netCarCompanyForm.disabled" type="date" size="default" v-model="netCarCompanyForm.foundedTime" placeholder="选择日期" style="width: 200px"></Date-picker>
                            </Form-item>
                        </i-col>
                        <i-col span="8">
                            <Form-item label="在运营网约车数量" prop="operateVehicles">
                                <Input v-bind:disabled="netCarCompanyForm.disabled"
                                       @on-change="changePeopleCarCardComplete"
                                       type="text" size="default" v-model="netCarCompanyForm.operateVehicles" clearable
                                       placeholder="请输入"
                                       style="width: 200px"/>
                            </Form-item>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col span="8">
                            <Form-item label="注册资本" prop="registeredCapital">
                                <Input v-bind:disabled="netCarCompanyForm.disabled" maxlength="14" type="text"
                                       size="default" v-model="netCarCompanyForm.registeredCapital" clearable
                                       placeholder="请输入"
                                       style="width: 200px"/>
                            </Form-item>
                        </i-col>
                        <i-col span="8">
                            <Form-item label="法人姓名" prop="legalPersonName">
                                <Input v-bind:disabled="netCarCompanyForm.disabled" type="text" size="default"
                                       v-model="netCarCompanyForm.legalPersonName" clearable placeholder="请输入"
                                       style="width: 200px"/>
                            </Form-item>
                        </i-col>
                        <i-col span="8">
                            <Form-item label="人证完备数" prop="peopleCardComplete">
                                <Input v-bind:disabled="netCarCompanyForm.disabled" type="text" size="default"
                                       v-model="netCarCompanyForm.peopleCardComplete" clearable placeholder="请输入"
                                       style="width: 200px"/>
                            </Form-item>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col span="8">
                            <Form-item label="联系方式" prop="legalPersonTel">
                                <Input v-bind:disabled="netCarCompanyForm.disabled" type="text" size="default"
                                       v-model="netCarCompanyForm.legalPersonTel" clearable placeholder="请输入"
                                       style="width: 200px"/>
                            </Form-item>
                        </i-col>
                        <i-col span="8">
                            <Form-item label="合作平台" prop="cooperPlat">
                                <Select v-bind:disabled="netCarCompanyForm.disabled"
                                        v-model="netCarCompanyForm.cooperPlat"
                                        multiple size="default" style="width: 200px">
                                    <Option v-for="item in cooperList" :value="item.code" :key="item.code" :label="item.name">{{ item.name }}</Option>
                                </Select>
                            </Form-item>
                        </i-col>
                        <i-col span="8">
                            <Form-item label="车证完备数" prop="carCardComplete">
                                <Input v-bind:disabled="netCarCompanyForm.disabled" type="text" size="default"
                                       v-model="netCarCompanyForm.carCardComplete" clearable placeholder="请输入"
                                       style="width: 200px"/>
                            </Form-item>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col span="8">
                            <Form-item label="法人身份证号码" prop="legalPersonIdcard">
                                <Input v-bind:disabled="netCarCompanyForm.disabled" type="text" size="default"
                                       v-model="netCarCompanyForm.legalPersonIdcard" clearable placeholder="请输入"
                                       style="width: 200px"/>
                            </Form-item>
                        </i-col>
                        <i-col span="8">
                            <Form-item label="网约车合作有效期" prop="channelTermValidity">
                                <Date-picker v-bind:disabled="netCarCompanyForm.disabled" :options="options3" type="date" size="default"
                                             v-model="netCarCompanyForm.channelTermValidity" placeholder="选择日期"
                                             style="width: 200px"></Date-picker>
                            </Form-item>
                        </i-col>
                        <i-col span="8">
                            <FormItem label="人证+车证完备数" prop="peoCarCardComplete">
                                <Input v-bind:disabled="netCarCompanyForm.disabled"
                                       @on-change="changePeopleCarCardComplete"
                                       type="text" size="default" v-model="netCarCompanyForm.peoCarCardComplete"
                                       clearable
                                       placeholder="请输入"
                                       style="width: 200px"/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col span="8">
                            <FormItem label="注册省市" prop="domicLocation">
                                <Cascader :data="location" v-model="netCarCompanyForm.domicLocation"
                                          v-bind:disabled="netCarCompanyForm.disabled" style="width:200px;"
                                          size="default" :clearable=false
                                          :load-data="loadData"></Cascader>
                            </FormItem>
                        </i-col>
                        <i-col span="8">
                            <form-item label="详细地址" prop="registeredAddress">
                                <Input v-bind:disabled="netCarCompanyForm.disabled"
                                       v-model="netCarCompanyForm.registeredAddress" size="default" style="width: 200px"
                                       placeholder="请输入"/>
                            </form-item>
                        </i-col>
                        <i-col span="8">
                            <Form-item label="人证+车证完备比例（%）" prop="peoCarCardProportion">
                                <Input disabled type="text" size="default"
                                       v-model="netCarCompanyForm.peoCarCardProportion"
                                       clearable placeholder="自动计算"
                                       style="width: 200px"/>
                            </Form-item>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col span="8">
                            <FormItem label="申请时间" id="applyTime">
                                <Date-picker type="date" v-model="netCarCompanyForm.applyTime" size="default" disabled
                                             style="width: 200px"></Date-picker>
                            </FormItem>

                        </i-col>
                        <i-col span="8">
                            <Form-item label="合作商名称" prop="channelId">
                                <Select class="selectOption" v-model="netCarCompanyForm.channelId" filterable clearable disabled
                                        style="width: 200px;" size="default">
                                    <Option v-for="item in baseInfo" :value='item.id' :key="item.id">{{item.channelFullName}}</Option>
                                </Select>
                            </Form-item>
                        </i-col>
                    </Row>
                    <Row>
                        <Button @click="openFileUpload" size="large"
                                style="float: right; color: #2b85e4;   background-color:white;border: none"
                                id="setUploadOrSee">上传附件
                        </Button>
                    </Row>
                </Form>
                <div v-if="isShowFile">
                    <!--附件-->
                    <file-operation  :uploadParam="uploadParam" :isInt="canUpload" :path="path" :read-only="readonly"></file-operation>
                </div>
            </div>
            <Modal :title="modalTitle" v-model="blackApplyVisible" :mask-closable='false' :width="500"
                   :styles="{top: '100px'}">
                <Form ref="blackApplyForm" :label-width="70">
                    <FormItem label="申请原因" prop="blacklistReason">
                        <Input v-model="blacklistReason" class="w400" placeholder="请输入黑名单申请原因" type="textarea"
                               :rows="6"/>
                    </FormItem>
                </Form>
                <div slot="footer" style="text-align:center;">
                    <Button type="text" @click="cancel">取消</Button>
                    <Button type="primary" @click="join">提交</Button>
                </div>
            </Modal>
        </div>
    </card>
</template>

<script>
    import {
        addNetCarAffiliationInfo,
        upDateAffiliationInfo,
        saveBlack,
        checkBlack,
        getAffiliationInfoById,
        getMainAreaById
    }  from "@/projects/afs-apply/api/affiliation/affiliationAddEdit";
    import { getChannelBaseInfo,getChannelId } from "@/projects/afs-apply/api/register-mng/listRecord";
    import {getAreaValueById,getLocation} from "_p/afs-apply/api/apply-report/personal/common";
    import {checkFile} from "_p/basic/api/image/image-upload";
    import FileOperation from "_p/basic/pages/image/upload-file/fileOperation.vue";
    import FilePreview from "_p/basic/pages/image/upload-file/contractFile/preview";
    import * as applyUtils from '_p/afs-apply/assets/js/utils.js'
    export default {
        components: {
            FileOperation,
            FilePreview,
        },
        data() {
            const validateMobile = (rule, value, callback) => {
                let reg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
                if (!reg.test(value)) {
                    callback(new Error("手机号格式错误"));
                } else {
                    callback();
                }
            };
            const validateCapital = (rule, value, callback) => {
                let reg = 500000;
                if (reg > value) {
                    callback(new Error("注册资本不能少于50万"));
                } else {
                    callback();
                }
            };
            const validatePeoCarCardProportion = (rule, value, callback) => {
                let reg = 60;
                if (reg > value) {
                    callback(new Error("人证+车证比例不能少于60"));
                } else {
                    callback();
                }
            };
            const validateVehicles = (rule, value, callback) => {
                let reg = 20;
                if (reg > value) {
                    callback(new Error("在运营车辆不少于20"));
                } else {
                    callback();
                }
            };

            const validateOperationYears = (rule, value, callback) => {
                let reg = 0.5;
                if (reg > value) {
                    callback(new Error("已运营年限不能少于0.5"));
                } else {
                    callback();
                }
            };
            const validIdCardNum = (rule, value, callback) => {
                //长度校验
                if (value != "") {
                    if (value.length != 18) {
                        return callback(new Error('输入有误，身份证号长度需为18位!'));
                    }
                    //格式和日期校验
                    let pattern = /^\d{6}(1[8-9]|[2-9][0-9])\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\d{3}(\d|X)$/;
                    if (!pattern.test(value)) {
                        return callback(new Error('输入有误，请检查身份证号格式!'));
                    }
                    //省份地址编码校验
                    var city = {
                        11: "北京",
                        12: "天津",
                        13: "河北",
                        14: "山西",
                        15: "内蒙古",
                        21: "辽宁",
                        22: "吉林",
                        23: "黑龙江 ",
                        31: "上海",
                        32: "江苏",
                        33: "浙江",
                        34: "安徽",
                        35: "福建",
                        36: "江西",
                        37: "山东",
                        41: "河南",
                        42: "湖北 ",
                        43: "湖南",
                        44: "广东",
                        45: "广西",
                        46: "海南",
                        50: "重庆",
                        51: "四川",
                        52: "贵州",
                        53: "云南",
                        54: "西藏 ",
                        61: "陕西",
                        62: "甘肃",
                        63: "青海",
                        64: "宁夏",
                        65: "新疆",
                        71: "台湾",
                        81: "香港",
                        82: "澳门",
                        91: "国外 "
                    };
                    if (!city[value.substr(0, 2)]) {
                        return callback(new Error('输入有误，请检查身份证号地址编码是否正确!'));
                    }
                    //最后一位校验码校验
                    if (value.length == 18) {
                        value = value.split('');
                        //∑(ai×Wi)(mod 11)
                        //加权因子
                        let factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
                        //校验位
                        let parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
                        let sum = 0;
                        let ai = 0;
                        let wi = 0;
                        for (let i = 0; i < 17; i++) {
                            ai = value[i];
                            wi = factor[i];
                            sum += ai * wi;
                        }
                        let last = parity[sum % 11];
                        if (last != value[17]) {
                            return callback(new Error('校验失败，请输入正确的身份证号!'));
                        }
                    }
                    return callback();
                } else {
                    return callback();
                }
            };
            let isSocValiate = (rule, value, callback) => {
                if (value) {
                    if (!applyUtils.isMoreCharNum(value)) {
                        callback(new Error("格式为英文与数字或纯数字"))
                        return;
                    } else {
                        if (value.length != 18) {
                            callback(new Error("社会统一信用代码位数为18位"))
                            return;
                        }
                    }
                }
                callback()
            };
            return {
                //附件部分
                readonly:false,
                uploadParam: {
                    busiNo: "",
                    belongNo: "",
                    busiType: "",
                    busiData: {}
                },
                canUpload:true,
                path:"apply",
                black: false, //是否显示黑名单申请对话框
                blacklistReason: null, // 申请黑名单原因
                moveComment: false,
                cooperList: [],
                channelList: [],
                location: [],
                affiliatedId: '',
                baseInfo:[],
                channelIdName:'',
                channelId:'',
                operCity: [],
                domicValue: "domicLocation",
                procity: [],
                sqqyids: "",
                saveType: 0,
                saleDate: '',
                options: {
                    disabledDate(date) {
                        return date && date.valueOf() > Date.now();
                    }
                },
                options3: {
                    disabledDate(date) {
                        return date && date.valueOf() < Date.now() - 86400000;
                    }
                },
                isShowFile: false,
                disabledSingle: true,
                spinShow: false,
                disabledGroup: '是',
                blackApplyVisible: false,
                loading: true,
                disabled: null,
                operationLoading: false,
                importLoading: false,
                loadingExport: true,
                // isOrNotApply:1,
                drop: false,
                dropDownContent: "展开",
                registeredProvinceCity: [],
                dropDownIcon: "ios-arrow-down",
                viewImage: false,
                selectDate: null,
                modelType: 0,
                userModalVisible: false,
                modalTitle: "",
                arrCooperPlat: [],
                updateStatus: '',
                is: {
                    disabled: null,
                },
                netCarCompanyForm: {
                    channelId: '',
                    busiType: "",
                    affiliatedName: '',
                    socUniCrtCode: "",
                    operationYears: '',
                    operCity: [],
                    foundedTime: "",
                    operateVehicles: '',
                    registeredCapital: '',
                    legalPersonName: '',
                    peopleCardComplete: '',
                    legalPersonTel: '',
                    cooperPlat: [],
                    carCardComplete: '',
                    legalPersonIdcard: '',
                    channelTermValidity: '',
                    peoCarCardComplete: '',
                    registeredProvince: "",
                    registeredCity: "",
                    registeredAddress: '',
                    peoCarCardProportion: '',
                    type: null,
                    isOrNotApply: 1,
                    limitValue: '',
                    warningValue: '',
                    // 省市用的
                    position: "",
                    domicLocation: [],
                    addressinfotwo: [
                        {
                            detailAddresstwo: [],

                        }
                    ]
                },
                netCarCompanyFormValidate: {
                    affiliatedName: [
                        {required: true, message: "运营公司名称不能空", trigger: "blur"}
                    ],
                    socUniCrtCode: [
                        {required: true, message: "社会统一信用代码不能空", trigger: "blur"},
                        {validator:isSocValiate,trigger: 'blur'}
                    ],
                    legalPersonIdcard: [
                        {
                            type: "string", max: 18, min: 18,
                            pattern: /^\d{6}(1[8-9]|[2-9][0-9])\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/,
                            message: "请输入正确的身份证号",
                            trigger: "blur"
                        },
                        {validator: validIdCardNum, trigger: 'blur'}
                    ],
                    operationYears: [
                        {required: true, message: "运营年限不能空", trigger: "blur"},
                        {validator: validateOperationYears, trigger: "change"}
                    ],
                    peopleCardComplete: [
                        {required: true, message: "人证完备数不能空", trigger: "blur"},
                        {
                            type: 'number', message: '应输入数字',
                            transform(value) {
                                return Number(value);
                            }
                        }
                    ],
                    carCardComplete: [
                        {required: true, message: "车证完备数不能空", trigger: "blur"},
                        {
                            type: 'number', message: '应输入数字',
                            transform(value) {
                                return Number(value);
                            }
                        }
                    ],
                    peoCarCardProportion: [
                        {required: true, message: "人证+车证完备比例不能空"},
                        {validator: validatePeoCarCardProportion, trigger: "change"}
                    ],
                    foundedTime: [
                        {required: true, type: 'date', message: "注册时间不能空", trigger: "blur"}
                    ],
                    operateVehicles: [
                        {required: true, message: "在运营网约车数量不能空", trigger: "blur"},
                        {
                            type: 'number', message: '应输入数字',
                            transform(value) {
                                return Number(value);
                            }
                        },
                        {validator: validateVehicles, trigger: "blur"}
                    ],
                    registeredCapital: [
                        {required: true, message: "注册资本不能空", trigger: "blur"},
                        {
                            type: 'number', message: '应输入数字',
                            transform(value) {
                                return Number(value);
                            }
                        },
                        // {validator: validateCapital, trigger: "blur"}
                    ],
                    legalPersonName: [
                        {required: true, message: "法人姓名不能空", trigger: "blur"}
                    ],
                    legalPersonTel: [
                        {required: true, message: "联系电话不能空", trigger: "blur"},
                        {validator: validateMobile, trigger: "blur"}
                    ],
                    cooperPlat: [
                        {required: true, type: 'array', message: "合作平台不能空", trigger: "blur"}
                    ],
                    channelTermValidity: [
                        {required: true, type: 'date', message: "网约车合作有效期不能空", trigger: "blur"}
                    ],
                    peoCarCardComplete: [
                        {required: true, message: "人证+车证完备数不能空", trigger: "blur"}
                    ],
                    registeredAddress: [
                        {required: true, message: "注册地址不能空", trigger: "blur"}
                    ],
                    domicLocation: [
                        {required: true, message: "注册省市不能为空", trigger: "blur", type: "array"}
                    ],
                    channelId: [
                        {required: true, message: "合作商名称不能空", trigger: "change"}
                    ],
                },
                submitLoading: false
            };
        },
        methods: {
            closeThisTag() {
                this.afs.closeTab(this);
                this.$router.push({path: '/affiliationApplyNetCar'});
            },
            socValite(){
                this.netCarCompanyForm.socUniCrtCode=this.netCarCompanyForm.socUniCrtCode.toUpperCase();
            },
            getById() {
                getAffiliationInfoById({id: this.netCarCompanyForm.id,channelId:this.netCarCompanyForm.channelId}).then(res => {
                    this.operationLoading = false;
                    if (res.code === "0000") {
                        if (this.modelType == 1) {
                            this.disabled = "disabled";
                        } else if (this.modelType === 2) {
                            let setUploadOrSee = document.getElementById("setUploadOrSee");
                            this.readonly=true;
                            setUploadOrSee.innerText = "查看附件";
                            this.disabled = "disabled";
                            this.is.disabled = "disabled";
                            this.netCarCompanyForm.disabled = "disabled";
                        }
                        this.netCarCompanyForm = res.data;
                        this.isOrNotApply =this.netCarCompanyForm.isOrNotApply;
                        // this.netCarCompanyForm.isOrNotApply =this.isOrNotApply;
                        this.netCarCompanyForm.channelId=this.channelIdName;
                        this.netCarCompanyForm.operationYears = this.netCarCompanyForm.operationYears.toString();
                        if (typeof this.netCarCompanyForm.registeredCapital != "undefined") {
                            this.netCarCompanyForm.registeredCapital = this.netCarCompanyForm.registeredCapital.toString();
                        }
                        if (typeof this.netCarCompanyForm.operateVehicles != "undefined") {
                            this.netCarCompanyForm.operateVehicles = this.netCarCompanyForm.operateVehicles.toString();
                        }
                        if (typeof this.netCarCompanyForm.peopleCardComplete != "undefined") {
                            this.netCarCompanyForm.peopleCardComplete = this.netCarCompanyForm.peopleCardComplete.toString();
                        }
                        if (typeof this.netCarCompanyForm.peoCarCardComplete != "undefined") {
                            this.netCarCompanyForm.peoCarCardComplete = this.netCarCompanyForm.peoCarCardComplete.toString();
                        }
                        if (typeof this.netCarCompanyForm.carCardComplete != "undefined") {
                            this.netCarCompanyForm.carCardComplete = this.netCarCompanyForm.carCardComplete.toString();
                        }
                        if (typeof this.netCarCompanyForm.warningValue != "undefined") {
                            this.netCarCompanyForm.warningValue = this.netCarCompanyForm.warningValue.toString();
                        }
                        if (typeof this.netCarCompanyForm.limitValue != "undefined") {
                            this.netCarCompanyForm.limitValue = this.netCarCompanyForm.limitValue.toString();
                        }
                        // 地址信息
                        this.netCarCompanyForm.domicLocation = [
                            this.netCarCompanyForm.registeredProvince,
                            this.netCarCompanyForm.registeredCity
                        ];
                        this.netCarCompanyForm.operCity = this.netCarCompanyForm.operCity.split(",");
                        this.netCarCompanyForm.addressinfotwo = [{detailAddresstwo: [this.netCarCompanyForm.operCity[0], this.netCarCompanyForm.operCity[1]],}];
                        let cooper = this.netCarCompanyForm.cooperPlat.split(",");
                        this.netCarCompanyForm.cooperPlat = cooper;

                    }
                });
            },

            Commit(name) {
                this.netCarCompanyForm.operationYears = this.netCarCompanyForm.operationYears.toString();
                if (this.netCarCompanyForm.foundedTime != "") {
                    this.netCarCompanyForm.foundedTime = new Date(this.netCarCompanyForm.foundedTime);
                }
                if (this.netCarCompanyForm.channelTermValidity != "") {
                    this.netCarCompanyForm.channelTermValidity = new Date(this.netCarCompanyForm.channelTermValidity);
                }
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        if(Number.parseFloat(this.netCarCompanyForm.warningValue)>Number.parseFloat(this.netCarCompanyForm.limitValue)){
                            this.$Message.error("预警值不能大于限额值");
                            return;
                        }
                        this.uploadParam.busiNo = this.netCarCompanyForm.id;
                        this.uploadParam.belongNo = this.netCarCompanyForm.id
                        this.uploadParam.busiData = {};
                        this.uploadParam.busiType = "affiliateApplyNet";
                        checkFile(this.uploadParam).then(res => {
                            if (res.code === '0000') {
                        if (this.modelType == 0) {
                            if (this.procity.length != 0 && (this.procity.indexOf(this.netCarCompanyForm.domicLocation[0]) == -1 || this.procity.indexOf(this.netCarCompanyForm.domicLocation[1]) == -1)) {
                                this.$Message.error(
                                    {content:"当前注册地址不在该合作商的授权区域内！",
                                        duration: 3
                                    });
                            } else {
                                let params = {
                                    blacklistType: '02',
                                    idType: '02',
                                    idCode: this.netCarCompanyForm.socUniCrtCode,
                                }
                                checkBlack(params).then(res => {
                                    if (res.code === "0000") {
                                        if (res.weatherBlackList == "0") {
                                            this.netCarCompanyForm.registeredProvince = this.netCarCompanyForm.domicLocation[0];
                                            this.netCarCompanyForm.registeredCity = this.netCarCompanyForm.domicLocation[1];
                                            this.netCarCompanyForm.registeredProvince = this.netCarCompanyForm.domicLocation[0];
                                            this.netCarCompanyForm.registeredCity = this.netCarCompanyForm.domicLocation[1];
                                            if (this.netCarCompanyForm.addressinfotwo[0].detailAddresstwo.length > 0) {
                                                this.netCarCompanyForm.operCity = this.netCarCompanyForm.addressinfotwo[0].detailAddresstwo[0] + "," + this.netCarCompanyForm.addressinfotwo[0].detailAddresstwo[1];
                                            } else {
                                                this.netCarCompanyForm.operCity = "";
                                            }
                                            let cooperPlat = "";
                                            this.netCarCompanyForm.isOrNotApply = 1;
                                            this.arrCooperPlat = this.netCarCompanyForm.cooperPlat;
                                            for (let i = 0; i < this.arrCooperPlat.length; i++) {
                                                if (i == this.arrCooperPlat.length - 1) {
                                                    cooperPlat += this.arrCooperPlat[i];
                                                } else {
                                                    cooperPlat += this.arrCooperPlat[i] + ",";
                                                }
                                            }
                                            ;
                                            this.netCarCompanyForm.saveOrCommit = "commit";
                                            this.netCarCompanyForm.busiType = "03";
                                            this.netCarCompanyForm.cooperPlat = cooperPlat;
                                            this.netCarCompanyForm.operationYears = Number(this.netCarCompanyForm.operationYears);
                                                if (this.affiliatedId == "") {
                                                    addNetCarAffiliationInfo(this.netCarCompanyForm).then(resAdd => {
                                                        this.submitLoading = false;
                                                        if (resAdd.code === "0000") {
                                                            if (!resAdd.data) {
                                                                this.$Message.error(resAdd.msg);
                                                                this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                            } else {
                                                                this.$Message.success("保存成功");
                                                                this.userModalVisible = false;
                                                                this.afs.closeTab(this);
                                                                this.$router.push({path: '/affiliationApplyNetCar'});
                                                            }
                                                        } else {
                                                            this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                        }
                                                    }).catch(() => {
                                                        this.submitLoading = false;
                                                        this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                    });
                                                } else {
                                                    this.netCarCompanyForm.id = this.affiliatedId;
                                                    upDateAffiliationInfo(this.netCarCompanyForm).then(resAdd => {
                                                        this.submitLoading = false;
                                                        if (resAdd.code === "0000") {
                                                            if (!resAdd.data) {
                                                                this.$Message.error(resAdd.msg);
                                                                this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                            } else {
                                                                this.$Message.success("保存成功");
                                                                this.userModalVisible = false;
                                                                this.afs.closeTab(this);
                                                                this.$router.push({path: '/affiliationApplyNetCar'});
                                                            }
                                                        } else {
                                                            this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                        }
                                                    }).catch(() => {
                                                        this.submitLoading = false;
                                                        this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                    });
                                                }

                                        } else {
                                            this.$Message.error("该挂靠公司已被加入黑名单");
                                        }
                                    }
                                }).catch(() => {
                                });
                            }
                        } else {
                            let params = {
                                blacklistType: '02',
                                idType: '02',
                                idCode: this.netCarCompanyForm.socUniCrtCode,
                            }
                            checkBlack(params).then(res => {
                                if (res.code === "0000") {
                                    if (res.weatherBlackList == "0") {
                                        this.netCarCompanyForm.registeredProvince = this.netCarCompanyForm.domicLocation[0];
                                        this.netCarCompanyForm.registeredCity = this.netCarCompanyForm.domicLocation[1];
                                        if (this.netCarCompanyForm.addressinfotwo[0].detailAddresstwo.length > 0) {
                                            this.netCarCompanyForm.operCity = this.netCarCompanyForm.addressinfotwo[0].detailAddresstwo[0] + "," + this.netCarCompanyForm.addressinfotwo[0].detailAddresstwo[1];
                                        } else {
                                            this.netCarCompanyForm.operCity = "";
                                        }
                                        ;
                                        let cooperPlat = "";
                                        this.arrCooperPlat = this.netCarCompanyForm.cooperPlat;
                                        for (let i = 0; i < this.arrCooperPlat.length; i++) {
                                            if (i == this.arrCooperPlat.length - 1) {
                                                cooperPlat += this.arrCooperPlat[i];
                                            } else {
                                                cooperPlat += this.arrCooperPlat[i] + ",";
                                            }
                                        }
                                        ;
                                        this.netCarCompanyForm.isOrNotApply = 1;
                                        this.netCarCompanyForm.saveOrCommit = "commit";
                                        this.netCarCompanyForm.busiType = "03";
                                        this.netCarCompanyForm.cooperPlat = cooperPlat;
                                        this.netCarCompanyForm.operationYears = Number(this.netCarCompanyForm.operationYears);
                                            if (this.affiliatedId == "") {
                                                addNetCarAffiliationInfo(this.netCarCompanyForm).then(resAdd => {
                                                    this.submitLoading = false;
                                                    if (resAdd.code === "0000") {
                                                        if (!resAdd.data) {
                                                            this.$Message.error(resAdd.msg);
                                                            this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                        } else {
                                                            this.$Message.success("保存成功");
                                                            this.userModalVisible = false;
                                                            this.afs.closeTab(this);
                                                            this.$router.push({path: '/affiliationApplyNetCar'});
                                                        }
                                                    } else {
                                                        this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                    }
                                                }).catch(() => {
                                                    this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                    this.submitLoading = false;
                                                });
                                            } else {
                                                this.netCarCompanyForm.id = this.affiliatedId;
                                                upDateAffiliationInfo(this.netCarCompanyForm).then(resAdd => {
                                                    this.submitLoading = false;
                                                    if (resAdd.code === "0000") {
                                                        if (!resAdd.data) {
                                                            this.$Message.error(resAdd.msg);
                                                            this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                        } else {
                                                            this.$Message.success("保存成功");
                                                            this.userModalVisible = false;
                                                            this.afs.closeTab(this);
                                                            this.$router.push({path: '/affiliationApplyNetCar'});
                                                        }
                                                    } else {
                                                        this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                    }
                                                }).catch(() => {
                                                    this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                    this.submitLoading = false;
                                                });
                                            }
                                    } else {
                                        this.$Message.error("该挂靠公司已被加入黑名单");
                                    }
                                }
                            }).catch(() => {
                            });
                        } }else{this.$Message.error("请补全影像件信息！");}
                        });
                    } else {
                        this.$Message.error('请补全信息');
                    }
                })
            },
            Save(name) {
                this.netCarCompanyForm.operationYears = this.netCarCompanyForm.operationYears.toString();
                if (this.netCarCompanyForm.foundedTime != "") {
                    this.netCarCompanyForm.foundedTime = new Date(this.netCarCompanyForm.foundedTime);
                }
                if (this.netCarCompanyForm.channelTermValidity != "") {
                    this.netCarCompanyForm.channelTermValidity = new Date(this.netCarCompanyForm.channelTermValidity);
                }
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        let params = {
                            blacklistType: '02',
                            idType: '02',
                            idCode: this.netCarCompanyForm.socUniCrtCode,
                        }
                        checkBlack(params).then(res => {
                            if (res.code === "0000") {
                                if (res.weatherBlackList == "0") {
                                    this.netCarCompanyForm.registeredProvince = this.netCarCompanyForm.domicLocation[0];
                                    this.netCarCompanyForm.registeredCity = this.netCarCompanyForm.domicLocation[1];
                                    if (this.netCarCompanyForm.addressinfotwo[0].detailAddresstwo[0] === "") {
                                        this.netCarCompanyForm.operCity = "";
                                    } else {
                                        this.netCarCompanyForm.operCity = this.netCarCompanyForm.addressinfotwo[0].detailAddresstwo[0] + "," + this.netCarCompanyForm.addressinfotwo[0].detailAddresstwo[1];
                                    }
                                    let cooperPlat = "";
                                    this.arrCooperPlat = this.netCarCompanyForm.cooperPlat;
                                    for (let i = 0; i < this.arrCooperPlat.length; i++) {
                                        if (i == this.arrCooperPlat.length - 1) {
                                            cooperPlat += this.arrCooperPlat[i];
                                        } else {
                                            cooperPlat += this.arrCooperPlat[i] + ",";
                                        }
                                    }
                                    ;
                                    this.netCarCompanyForm.cooperPlat = cooperPlat;
                                    this.netCarCompanyForm.busiType = "03";
                                    this.netCarCompanyForm.saveOrCommit = "save";
                                    this.netCarCompanyForm.operationYears = Number(this.netCarCompanyForm.operationYears);
                                    this.spinShow = true;
                                    if (this.affiliatedId == "") {
                                        addNetCarAffiliationInfo(this.netCarCompanyForm).then(resAdd => {
                                            this.submitLoading = false;
                                            if (resAdd.code === "0000") {
                                                if (!resAdd.data) {
                                                    this.spinShow = false;
                                                    this.$Message.error(resAdd.msg);
                                                    this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                } else {
                                                    this.spinShow = false;
                                                    this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                    this.$Message.success("保存成功");
                                                    this.userModalVisible = false;
                                                    this.affiliatedId = resAdd.data;
                                                    this.netCarCompanyForm.id = this.affiliatedId;
                                                }
                                            } else {
                                                this.spinShow = false;
                                                this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                            }
                                        })
                                    } else {
                                        upDateAffiliationInfo(this.netCarCompanyForm).then(resAdd => {
                                            this.submitLoading = false;
                                            if (resAdd.code === "0000") {
                                                if (!resAdd.data) {
                                                    this.spinShow = false;
                                                    this.$Message.error(resAdd.msg);
                                                    this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                } else {
                                                    this.spinShow = false;
                                                    this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                                    this.$Message.success("保存成功");
                                                    this.userModalVisible = false;
                                                    this.affiliatedId = resAdd.data.id;
                                                    this.netCarCompanyForm.id = this.affiliatedId;
                                                }
                                            } else {
                                                this.spinShow = false;
                                                this.netCarCompanyForm.cooperPlat = this.arrCooperPlat;
                                            }
                                        })
                                    }
                                } else {
                                    this.$Message.error("该挂靠公司已被加入黑名单");
                                }
                            }
                        })
                    }else{
                        this.$Message.error('请补全信息');
                    }
                })
            },
            getCooperList() {
                this.cooperList = [{code: "01", name: "滴滴"}, {code: "02", name: "快车"}, {code: "03", name: "百度"}, {
                    code: "04",
                    name: "大众"
                }];
            },
            blacklist() {
                this.modalTitle = "确认将合作商加入黑名单吗？";
                this.blackApplyVisible = true;
            },
            cancel() {
                //关闭黑名单窗口
                this.blackApplyVisible = false;
            },
            // 申请加入黑名单
            join() {
                if (this.blacklistReason == null || this.blacklistReason == '' || this.blacklistReason == undefined) {
                    this.$Message.error('请输入申请原因');
                    return;
                }
                let parms = {
                    blacklistType: '02',
                    idType: '02',
                    idCode: this.netCarCompanyForm.socUniCrtCode,
                    blacklistReason: this.blacklistReason,
                    blackName: this.netCarCompanyForm.affiliatedName
                }
                saveBlack(parms).then(res => {
                    if (res.code === "0000") {
                        this.$Message.success("申请成功！");
                        this.cancel();
                    }
                }).catch(() => {

                });
            }
            ,
            getLocationData() {
                let param = ""
                param = {
                    level: '1',
                    upperCode: '1'
                };
                getLocation(param).then((res) => {
                    if (res.code == "0000") {
                        res.data.forEach(item => {
                            // 表明是否是父节点
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        })
                    }
                    this.location.push(...res.data);
                })
            }
            ,
            loadData(item, callback) {
                // console.log("是否调用新车")
                item.loading = true;
                getLocation({upperCode: item.value}).then(res => {
                    if (res.code === "0000") {
                        res.data.forEach(function (item) {
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        });
                        item.children = res.data;
                        item.loading = false;
                        callback();
                    }
                })
            },
            changeOperationYears(e) {
                if (e != null && e != "") {
                    let foundDate = new Date(e.replace(/\-/g, "/")).getTime();
                    let date = new Date(new Date().setHours(0, 0, 0, 0)).getTime();
                    let time = date - foundDate;
                    let days = time / (3600 * 24 * 1000) / 366;
                    let operationYear = days.toFixed(10);
                    operationYear = operationYear.substring(0, operationYear.lastIndexOf('.') + 2);
                    this.netCarCompanyForm.operationYears = operationYear;
                } else {
                    this.netCarCompanyForm.operationYears = 0;
                }
            }
            ,
            changePeopleCarCardComplete() {
                if (this.netCarCompanyForm.peoCarCardComplete != "" && this.netCarCompanyForm.operateVehicles != "") {
                    this.netCarCompanyForm.peoCarCardProportion = Math.round((this.netCarCompanyForm.peoCarCardComplete) / (this.netCarCompanyForm.operateVehicles) * 100);
                } else {
                    this.netCarCompanyForm.peoCarCardProportion = "";
                }
            }
            ,
            // 获取当前时间
            getTime() {
                var date = new Date();
                var year = date.getFullYear(); //年 ,从 Date 对象以四位数字返回年份
                var month = date.getMonth() + 1; //月 ,从 Date 对象返回月份 (0 ~ 11) ,date.getMonth()比实际月份少 1 个月
                var day = date.getDate(); //日 ,从 Date 对象返回一个月中的某一天 (1 ~ 31)
                var hours = date.getHours(); //小时 ,返回 Date 对象的小时 (0 ~ 23)
                var minutes = date.getMinutes(); //分钟 ,返回 Date 对象的分钟 (0 ~ 59)
                var seconds = date.getSeconds(); //秒 ,返回 Date 对象的秒数 (0 ~ 59)
                //修改月份格式
                if (month >= 1 && month <= 9) {
                    month = "0" + month;
                }
                //修改日期格式
                if (day >= 0 && day <= 9) {
                    day = "0" + day;
                }
                //修改小时格式
                if (hours >= 0 && hours <= 9) {
                    hours = "0" + hours;
                }
                //修改分钟格式
                if (minutes >= 0 && minutes <= 9) {
                    minutes = "0" + minutes;
                }
                //修改秒格式
                if (seconds >= 0 && seconds <= 9) {
                    seconds = "0" + seconds;
                }
                //格式(yyyy-mm-dd hh:mm:ss)
                var currentFormatDate =
                    year +
                    "-" +
                    month +
                    "-" +
                    day +
                    " " +
                    hours +
                    ":" +
                    minutes +
                    ":" +
                    seconds;
                this.netCarCompanyForm.applyTime = currentFormatDate;
            }
            ,
            getBaseInfo() {
                if (this.afs.getPageParams(this).type == 1) {
                    this.getTime();
                    this.modelType=0;
                    this.saveType=4;
                } else {
                    this.netCarCompanyForm.id = this.afs.getPageParams(this).id;
                    this.affiliatedId=this.netCarCompanyForm.id;
                    if(this.afs.getPageParams(this).type == 2){
                        this.updateStatus=this.afs.getPageParams(this).updateStatus;
                        if(this.updateStatus =="05"){
                            this.is.disabled="disabled";
                            this.saveType=3;
                        }else{
                            this.saveType=4;
                        }
                        this.modelType=1;
                    }else if(this.afs.getPageParams(this).type == 3){
                        this.modelType=2;
                        if(this.updateStatus =="00"){
                            this.showType=1;
                        }
                        this.readonly=true;
                    }
                };
                getChannelBaseInfo({status: "00"}).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        this.baseInfo = res.data;
                        let baseInfoList=res.data;
                        getChannelId({}).then(ress => {
                            if (ress.code === "0000") {
                                   // let channelId = "4701178224791771020";
                                // let channelId = "4460600613838667776";
                                 let channelId = ress.data;
                                this.channelId=channelId;
                                for(let i=0;i<baseInfoList.length;i++){
                                    if(channelId==baseInfoList[i].id){
                                        this.netCarCompanyForm.channelId = baseInfoList[i].id;
                                        this.channelIdName=this.netCarCompanyForm.channelId;
                                        this.sqqyids="";
                                        this.procity=[];
                                        let param={
                                            id:this.netCarCompanyForm.channelId
                                        };
                                        getMainAreaById(param).then(resMainArea => {
                                            this.loading = false;
                                            if (resMainArea.code === "0000") {
                                                for(var i=0;i<resMainArea.data.length;i++){
                                                    if(i!=resMainArea.data.length-1){
                                                        this.sqqyids+=resMainArea.data[i].code+",";
                                                    }else{
                                                        this.sqqyids+=resMainArea.data[i].code;
                                                    }
                                                }
                                                if(this.sqqyids!="" && this.sqqyids!=null){
                                                    getAreaValueById({id:this.sqqyids}).then(res =>{
                                                            if(res.code==="0000"){
                                                                for(var i=0;i<res.data.length;i++){
                                                                    this.procity.push(res.data[i].value);
                                                                }
                                                            }
                                                        }
                                                    )
                                                }
                                                if (this.afs.getPageParams(this).type != 1) {
                                                    this.getById();
                                                };
                                            }
                                        })
                                    }
                                }
                            }
                        });
                    }
                });
            },
            openFileUpload() {
                this.isShowFile = !this.isShowFile;
                if(this.netCarCompanyForm.id){
                    this.initGetFilterParams();
                }else{
                    this.isShowFile=false;
                    this.$Message.error("请先保存数据");
                }
            },
            initGetFilterParams() {
                this.uploadParam.busiNo = this.netCarCompanyForm.id;
                this.uploadParam.belongNo = this.netCarCompanyForm.id
                this.uploadParam.busiData = {};
                this.uploadParam.busiType = "affiliateApplyNet";
            },
        },
        mounted() {
            // this.init();
            this.getBaseInfo();
            this.getCooperList();
            this.getLocationData();
            // this.getChannelList();
        }
    }
</script>

<style scoped>

</style>
